const mongoose = require('mongoose')
const Schema = mongoose.Schema

//嵌套文档
const tag = new Schema({
    id: {
        type: String,
        required: [true, "必填tag的id"],
        default: '0'
    },
    title: {
        type: String,
        required: [true, "必填tag的title"],
        default: '原神'
    }

})
//用户表结构
const AdminUserType = {
    username: {
        type: String,
        unique: true,
        required: true,
        minLength: [2, '最小长度为2'],
        maxLength: [6, '最大长度为6'],

    },
    password: {
        type: String,
        required: [true, "必填password"],

    },
    famous_sentence: {
        type: String,
        minLength: [5, '最小长度为5'],
        maxLength: [55, "最大长度为55"],
        default: "我将岁月尽扫，往事铺平，便正当当地看到了你，那一刹，如秋日寒潭旁的齐飞雁，如冬日山头前的最后一抹余晖。"
    },
    introduce: {
        type: String,
        minLength: [5, '最小长度为5'],
        maxLength: [30, "最大长度为30"],
        default: "三天打鱼两天晒网"
    },
    avatar: {
        type: String,
        default: ""
    },
    tags: {
        type: Array,
        tag: tag,
    },
    csdn: {
        type: String,
        default: ""
    },
    bilibili: {
        type: String,
        default: ""
    },
    gitee: {
        type: String,
        default: ""
    },
    qq: {
        type: String,
        default: "2253292026"
    },
    english_name: {
        type: String,
        default: "yangwanjun"
    },
    school: {
        type: String,
        default: "遂宁七中"
    },
    role: {
        type: String,
        enum: {
            values: ['0', '1'],
            message: "只能从0或1选择"
        },
        default: "0"
    }
}

//生成模型
const AdminUserModel = mongoose.model("user", new Schema(AdminUserType))

//导出模型
module.exports = AdminUserModel